/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaclientcp3110.Model;

import common.Objects.Product;
import java.util.Vector;
import common.Objects.Component;
import common.DAO.Factory.DAOFactory;
import common.Objects.Category;

/**
 * MainModel holds a single copy of the main code, that is, it is a singleton.
 * MainModel holds the current user, components and products to conserve memory
 * @author Richard Irons
 */
public class MainModel {
    private static MainModel instance;

    private Vector<Component> components;
    private Vector<Category> categorys;
    private Vector<Product> products;
    
    // user here etc...

    private MainModel() {
        updateData();
    }

    public void updateData(){
        updateComponents();
        updateCategorys();
        updateProducts();
        System.out.println();
    }
    public static MainModel getInstance() {
        if (instance == null) {
            instance = new MainModel();
        }
        return instance;
    }

    public Vector<Component> getComponents() {
        return components;
    }

    private void updateComponents() {
        this.components = DAOFactory.getDAOFactory().getComponentDAO().getComponents();
        if (this.components == null) {
            this.components = new Vector<Component>();
        }
    }
    
    public Vector<Category> getCategorys() {
        return categorys;
    }

    private void updateCategorys() {
        this.categorys = DAOFactory.getDAOFactory().getCategoryDAO().getCategorys();
        if (this.categorys == null) {
            this.categorys = new Vector<Category>();
        }
    }

    public Vector<Product> getProducts() {
        return products;
    }

    private void updateProducts() {
        this.products = DAOFactory.getDAOFactory().getProductDAO().getProducts();
        if (this.products == null) {
            this.products = new Vector<Product>();
        }
    }

}
